import {
    createSlice,
    createAsyncThunk
} from "@reduxjs/toolkit"


import {getMovieRequest} from '../../api/index'

//创建异步的Action
export const getMovieAction = createAsyncThunk("movie/getMovieList" , async() => {
    const re = await getMovieRequest()
    return re.data.data.list
})



//创建Slice
const movieSlice = createSlice({
    name: "movie",

    initialState: {
        movieList: []
    },

    reducers: {

    },

    extraReducers: {
        [getMovieAction.fulfilled](prev , action){
            prev.movieList = action.payload
        },
        [getMovieAction.rejected](prev , action){
             
        },
        [getMovieAction.pending](prev , action){
            
        }
    }

})

export default movieSlice.reducer